import request from '@/ya/request';
import { baseUrl, apiPath } from "@/ya/request/index.js";

const AdminApi = {
	// 导入用户信息
	exportUser: (data) => {
		return request({
			url: '/api/admin/import/user-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '用户导入成功!',
				showError: false, // 不展示错误提示
			},
		});
	},
	// 导入考点信息
	exportKD: (data) => {
		return request({
			url: '/api/admin/import/kd-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '考点导入成功!',
				showError: false, // 不展示错误提示
			},
		});
	},
	// 更新考点信息
	updateKD: (data) => {
		return request({
			url: '/api/admin/import/kd-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showError: false, // 不展示错误提示
			},
		});
	},
	// 导入楼层信息
	exportFloor: (data) => {
		return request({
			url: '/api/admin/import/floor-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '导入成功!',
				showError: false, // 不展示错误提示
			},
		});
	},
	// 获取是否有楼层
	getFloorStatus: (kdid) => {
		return request({
			url: '/api/admin/import/status/floor-info',
			method: 'GET',
			params: {kdid: kdid},
			custom: {
				showLoading: false,
				auth: true,
				showError: false, // 不展示错误提示
			},
		});
	},
	// 更新楼层信息
	updateFloor: (data) => {
		return request({
			url: '/api/admin/import/floor-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '导入成功!',
				showError: false, // 不展示错误提示
			},
		});
	},
	// 导入考生信息
	exportExamInfo: (data) => {
		return request({
			url: '/api/admin/import/examinee-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '导入成功!',
				showError: false,
			},
		});
	},
	// 更新考生信息
	updateExamInfo: (data) => {
		return request({
			url: '/api/admin/import/examinee-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新考生成功!',
				showError: false,
			},
		});
	},
	// 权限分配
	permissionFor: (data) => {
		return request({
			url: '/api/admin/import/user-permission',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '设置成功!',
				showError: false,
			},
		});
	},
	// 获取管理员列表
	getMangerList: (userType = '') => {
		return request({
			url: '/api/admin/problem-reports/users',
			method: 'GET',
			params: userType ? {userType: userType} : {},
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '设置成功!',
				showError: false,
			},
		});
	},
	// 根据用户uid去查对应的关联的考点信息
	getSitesDetaylByUID: (uid) => {
		return request({
			url: '/api/admin/problem-reports/exam-sites',
			method: 'GET',
			params: {uid: uid},
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '设置成功!',
				showError: false,
			},
		});
	},
	// 导入巡考员信息
	exportPatrolInfo: (data) => {
		return request({
			url: '/api/admin/import/patrol-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '导入成功!',
				showError: false,
			},
		});
	},
	// 更新巡考员信息
	updatePatrolInfo: (data) => {
		return request({
			url: '/api/admin/import/patrol-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新巡考员成功!',
				showError: false,
			},
		});
	},
	// 查询全部考点信息
	getAllKDList: () => {
		return request({
			url: '/api/admin/import/all/kd-info',
			method: 'POST',
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 分页查询考点信息
	getKDList: (data) => {
		return request({
			url: '/api/admin/import/page/kd-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 获取停车列表
	getAllExamList: () => {
		return request({
			url: '/api/admin/import/all/examinee-info',
			method: 'POST',
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 分页查询考生信息
	getExamList: (data) => {
		return request({
			url: '/api/admin/import/page/examinee-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 查询全部巡考员信息
	getAllPatrolList: () => {
		return request({
			url: '/api/admin/import/all/patrol-info',
			method: 'POST',
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 分页查询巡考员信息
	getPatrolList: (data) => {
		return request({
			url: '/api/admin/import/page/patrol-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 查询全部楼层信息
	getAllFloorList: () => {
		return request({
			url: '/api/admin/import/all/floor-info',
			method: 'POST',
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 分页查询楼层信息
	getFloorList: (data) => {
		return request({
			url: '/api/admin/import/page/floor-info',
			method: 'POST',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showError: false,
			},
		});
	},
	// 批量删除考点信息
	batchKd: (data) => {
		return request({
			url: `/api/admin/import/batch/kd-info`,
			method: 'DELETE',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 删除考点信息
	deleteKd: (id) => {
		return request({
			url: `/api/admin/import/kd-info/${id}`,
			method: 'DELETE',
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 批量删除楼层信息
	batchFloor: (data) => {
		return request({
			url: `/api/admin/import/batch/floor-info`,
			method: 'DELETE',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 删除楼层信息
	deleteFloor: (id) => {
		return request({
			url: `/api/admin/import/floor-info/${id}`,
			method: 'DELETE',
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 批量删除考生信息
	batchExaminee: (data) => {
		return request({
			url: `/api/admin/import/batch/examinee-info`,
			method: 'DELETE',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 删除考生信息
	deleteExaminee: (id) => {
		return request({
			url: `/api/admin/import/examinee-info/${id}`,
			method: 'DELETE',
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 批量删除巡考员信息
	batchPatrol: (data) => {
		return request({
			url: `/api/admin/import/batch/patrol-info`,
			method: 'DELETE',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 删除巡考员信息
	deletePatrol: (id) => {
		return request({
			url: `/api/admin/import/patrol-info/${id}`,
			method: 'DELETE',
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 批量删除用户信息
	batchUserInfo: (data) => {
		return request({
			url: `/api/admin/import/batch/user-info`,
			method: 'DELETE',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 删除用户信息
	deleteUserInfo: (id) => {
		return request({
			url: `/api/admin/import/user-info/${id}`,
			method: 'DELETE',
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 批量删除用户权限信息
	batchUserPermission: (data) => {
		return request({
			url: `/api/admin/import/batch/user-permission`,
			method: 'DELETE',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 删除用户权限信息
	deleteUserPermission: (id) => {
		return request({
			url: `/api/admin/import/user-permission/${id}`,
			method: 'DELETE',
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '删除成功!',
				showError: false,
			},
		});
	},
	// 批量更新考生信息
	batchUPExam: (data) => {
		return request({
			url: '/api/admin/import/batch/examinee-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新成功!',
				showError: false,
			},
		});
	},
	// 批量更新用户信息
	batchUPuser: (data) => {
		return request({
			url: '/api/admin/import/batch/user-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新成功!',
				showError: false,
			},
		});
	},
	// 批量更新楼层信息
	batchUPfloor: (data) => {
		return request({
			url: '/api/admin/import/batch/floor-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新成功!',
				showError: false,
			},
		});
	},
	// 批量更新考点信息
	batchUPkd: (data) => {
		return request({
			url: '/api/admin/import/batch/kd-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新成功!',
				showError: false,
			},
		});
	},
	// 批量更新巡考员信息
	batchUPpatrol: (data) => {
		return request({
			url: '/api/admin/import/batch/patrol-info',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新成功!',
				showError: false,
			},
		});
	},
	// 批量更新用户权限信息
	batchUPuserPermission: (data) => {
		return request({
			url: '/api/admin/import/batch/user-permission',
			method: 'PUT',
			data,
			custom: {
				showLoading: false,
				auth: true,
				showSuccess: true,
				successMsg: '更新成功!',
				showError: false,
			},
		});
	},
	// 上传图片
	uploadImg: (filePath, fileName) => {  // 参数应为文件路径/文件对象
	    return new Promise((resolve, reject) => {
	        wx.uploadFile({
	            url: baseUrl + apiPath + 'api/files/upload',
	            filePath: filePath,  // 确保参数名正确
	            name: 'file',
				formData: {
					filename: fileName // 自定义文件名参数
				},
	            success: (res) => {
	                // 添加响应处理
	                try {
	                    const data = JSON.parse(res.data)
	                    if (data.code === 200) {
	                        resolve(data)
	                    } else {
	                        reject(data)
	                    }
	                } catch(e) {
	                    reject({ message: '响应解析失败' })
	                }
	            },
	            fail: (err) => reject(err)  // 添加失败处理
	        })
	    })
	},
};

export default AdminApi;